﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Data.Model;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using ZLCMS.Business.DwzFrame;
using System.Reflection;
using NHibernate;


namespace ZLCMS.Web.SystemManage.Basics.MessageBoard
{
    public partial class EditMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitializeContent();
            }
            else
            {
                Save();
            }
        }

        private void Save()
        {
            FrameHelper frameHelper = new FrameHelper(this);

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                MessageInfo message = session.Get<MessageInfo>(int.Parse(Request["uid"]));

                message.Title = ip_title.Value;
                message.Content = ta_content.Value;
                message.Status = ddl_status.SelectedValue;

                session.Update(message);

                session.Flush();
            }

            frameHelper.Alert(new ReturnCode()
            {
                statusCode = 200,
                message = "操作成功!",
                callbackType = "closeCurrent",
                navTabId = frameHelper.NavTabId
            });
        }

        private void InitializeContent()
        {
            uid.Value = Request["uid"];

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                MessageInfo message = session.Get<MessageInfo>(int.Parse(Request["uid"]));
                ip_title.Value = message.Title;
                ta_content.Value = message.Content;
                ddl_status.SelectedValue = message.Status;
            }
        }
    }
}
